package com.lh.java.basic.threadlocal;

public class TestVolatile {	
	public volatile static int i=0;
	public static void main(String[] args) {
		for(int i=0;i<10000;i++){
			new threadI().start();
		}
		try {
			
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("main thread   i ="+TestVolatile.i);

	}

}
class threadI extends Thread{    
	@Override
	public void run() {			
		try {
			int sleep = (int) (Math.random()*10);
			Thread.sleep(sleep);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		TestVolatile.i++;
		System.out.println(Thread.currentThread().getName()+ "i = "+TestVolatile.i);
	}
	
}
